package com.cskaoyan.service;

import com.cskaoyan.dao.OrderDao;
import com.cskaoyan.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author stone
 * @date 2021/11/19 10:18
 */
//@Component("userService")
@Component   //组件id是userServiceImpl
public class UserServiceImpl implements UserService{

    //值直接写在注解的value属性里，就直接将值和成员变量耦合起来了
    //@Value("songge")
    //String username;
    //String username = "songge";

    @Value("${param.username}") //SpEL
    String username;

    //使用注入功能的注解：为了维护组件之间的依赖关系
    //就是给成员变量赋值 👉 值来源于容器

    //按照类型注入
    @Autowired
    UserDao userDao;

    //@Autowired + @Qualifier 通过其value属性额外指定了组件id
    @Autowired
    @Qualifier("orderDaoImpl")
    OrderDao orderDao1;

    //如果没有使用其属性，按照类型注入，如果要指定组件id，要使用其name属性
    @Resource(name = "orderDaoImpl2")
    OrderDao orderDao2;


    @Override
    public void sayHello() {
        userDao.daoSayHello();
        System.out.println("hello " + username);

        orderDao1.buy();
        orderDao2.buy();

    }
}
